****************************************************************************
*** Complaint Ressources & Representation in Int. Human Rights Bodies    ***
***          Author: Christoph Valentin Steinert                         ***
*** 	Replication files for a robustness test - Table A.6 			 ***
****************************************************************************

set seed 12345
set more off
version 13.0
clear

* Load data
use "analysisdata_study1.dta", clear

******************************************************************************
** GMM: Instrumental Variable Poisson with bootstrapped standard errors
******************************************************************************

*** Prepare variables
gen PTS_squared = PTS^2
gen PTS_lag2_squared = pts_lag_2^2
gen PTS_lag3_squared = pts_lag_3^2
gen Civil_society_lag2 = CSO_repress[_n-2]
gen Alt_complaint_proc_lag2 = Alt_complaint_proc[_n-2]
gen Clean_election_lag2 = Clean_election[_n-2]
gen Judicial_con_lag2 = Judicial_ind[_n-2]
gen NHRI_lag2 = NHRI[_n-2]
gen OHCHR_presence_lag2 = OHCHR_presence[_n-2]
gen GDPcap_log_lag2 = GDPcap_log[_n-2]
gen GDPcap_log_lag3 = GDPcap_log[_n-3]

*** Poisson model with bootstrapped SE (to compare to GMM-estimated model parameter estimates)
xtset, clear
set seed 040715
capture drop vhat*
#delimit ;
poisson comm_count PTS##PTS UN_language_franca GDPcap_log Alt_complaint_proc Clean_election Judicial_con 
NHRI Civil_society OHCHR_presence Population_log Armed_conflict i.year, vce(boot, reps(20) cl(COW_Code_A));
#delimit cr

* Endogeneity
#delimit ;
reg GDPcap_log PTS PTS_squared UN_language_franca Alt_complaint_proc Clean_election Judicial_con NHRI Civil_society OHCHR_presence Population_log Armed_conflict i.year PTS_lag2_squared PTS_lag3_squared, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat1, resid ;
poisson comm_count PTS PTS_squared UN_language_franca GDPcap_log Alt_complaint_proc Clean_election Judicial_con NHRI Civil_society OHCHR_presence Population_log Armed_conflict i.year vhat1, vce(boot, reps(20) cl(COW_Code_A)) ;
test vhat1 ;
#delimit cr

* Test of instruments
*** GDPcap_log
#delimit ;
reg GDPcap_log GDPcap_log_lag2 GDPcap_log_lag3 PTS_squared UN_language_franca Alt_complaint_proc Clean_election Judicial_con NHRI Civil_society OHCHR_presence Population_log Armed_conflict i.year, vce(boot, reps(50) cl(COW_Code_A));
#delimit cr
test GDPcap_log_lag2 GDPcap_log_lag3
*** statistically significant

** GMM 
xtset, clear
#delimit ;
ivpoisson gmm comm_count UN_language_franca PTS PTS_squared Alt_complaint_proc Clean_election Judicial_con 
NHRI Civil_society OHCHR_presence Population_log Armed_conflict (GDPcap_log = GDPcap_log_lag2 GDPcap_log_lag3),
 twostep vce(boot, reps(50) cl(COW_Code_A) seed(1)) ;
#delimit cr
estat overid

*** REPRODUCES MODEL(1) IN TABLE A.6 IN THE ONLINE APPENDIX ***
* Report results
mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".GMM_Tab1_Model1.tex",  ///
 ctitle("Model 1") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')


*******************************************************************************************************************
*** GMM: Instrumental Variable Poisson with bootstrapped standard errors: all endogenous variables instrumented ***
*******************************************************************************************************************

capture drop vhat3
capture drop vhat4
capture drop vhat5
capture drop vhat6
capture drop vhat7
capture drop vhat8

* these other variables could be potentially endogenous to shaming: 
* Alt_complaint_proc, Clean_election, Judicial_con, NHRI, Civil_society, OHCHR_presence, PTS
#delimit ;
reg Civil_society UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared Civil_society_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat3, resid ;
reg Alt_complaint_proc UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared Alt_complaint_proc_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat4, resid ;
reg Clean_election UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared Clean_election_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat5, resid ;
reg Judicial_con UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared Judicial_con_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat6, resid ;
reg NHRI UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared NHRI_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat7, resid ;
reg OHCHR_presence UN_language_franca GDPcap_log Population_log Armed_conflict PTS_squared OHCHR_presence_lag2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat8, resid ;
reg PTS OHCHR_presence UN_language_franca GDPcap_log Population_log Armed_conflict pts_lag_2, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat9, resid ;
reg PTS_squared OHCHR_presence UN_language_franca GDPcap_log Population_log Armed_conflict PTS_lag2_squared, vce(boot, reps(20) cl(COW_Code_A)) ;
predict vhat10, resid ;
poisson comm_count UN_language_franca GDPcap_log Population_log Armed_conflict GDPcap_log_lag2 GDPcap_log_lag3 PTS_lag2_squared OHCHR_presence_lag2 NHRI_lag2 Judicial_con_lag2 Clean_election_lag2 Alt_complaint_proc_lag2 Civil_society_lag2
vhat*, vce(boot, reps(20) cl(COW_Code_A)) ; 
test vhat3 vhat4 vhat5 vhat6 vhat7 vhat8 vhat9 vhat10;
test vhat3 ; // civil society statistically significant
test vhat4 ; 
test vhat5 ; // clean elections statistically significant
test vhat6 ; 
test vhat7 ; 
test vhat8 ; 
test vhat9 ; 
test vhat10 ; 
#delimit cr

* Lag3 for other EEV
gen Civil_society_lag3 = Civil_society[_n-3]
gen Clean_election_lag3 = Clean_election[_n-3]
gen Judicial_con_lag3 = Judicial_con[_n-3]
gen OHCHR_presence_lag3 = OHCHR_presence[_n-3]

** Test of instruments
tsset, clear
reg Civil_society_lag2 Civil_society PTS PTS_squared UN_language_franca GDPcap_log Population_log Armed_conflict Alt_complaint_proc Clean_election Judicial_con NHRI OHCHR_presence, vce(boot, reps(20) cl(COW_Code_A))
reg Civil_society_lag3 Civil_society PTS PTS_squared UN_language_franca GDPcap_log Population_log Armed_conflict Alt_complaint_proc Clean_election Judicial_con NHRI OHCHR_presence, vce(boot, reps(20) cl(COW_Code_A))
reg Clean_election_lag2 Clean_election OHCHR_presence Civil_society PTS PTS_squared UN_language_franca GDPcap_log Population_log Armed_conflict Alt_complaint_proc Clean_election Judicial_con NHRI, vce(boot, reps(20) cl(COW_Code_A))
reg Clean_election_lag3 Clean_election OHCHR_presence Civil_society PTS PTS_squared UN_language_franca GDPcap_log Population_log Armed_conflict Alt_complaint_proc  Judicial_con NHRI, vce(boot, reps(20) cl(COW_Code_A))


** GMM
xtset, clear
#delimit ;
ivpoisson gmm comm_count UN_language_franca Alt_complaint_proc OHCHR_presence NHRI Judicial_con OHCHR_presence
Population_log Armed_conflict (GDPcap_log Clean_election Civil_society PTS PTS_squared = GDPcap_log_lag2 GDPcap_log_lag3 Clean_election_lag2 Clean_election_lag3 Civil_society_lag2 Civil_society_lag3 pts_lag_2 pts_lag_3 PTS_lag2_squared), 
twostep vce(boot, reps(20) cl(COW_Code_A) seed(1)) ;
#delimit cr
estat overid 
* Hansen's J chi2: I can NOT reject the null hypothesis that instruments are uncorrelated with the errors; instruments ARE JOINTLY VALID

*** REPRODUCES MODEL(2) IN TABLE A.6 IN THE ONLINE APPENDIX ***
mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".endogenous_instrumented_true_GMM.tex", append ///
 ctitle("Model 6") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')








